<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
        <el-form-item label="员工ID:" prop="EmployeeId">
          <el-input v-model="formData.EmployeeId" :clearable="true"  placeholder="请输入员工ID" />
       </el-form-item>
        <el-form-item label="工号:" prop="EnCode">
          <el-input v-model="formData.EnCode" :clearable="true"  placeholder="请输入工号" />
       </el-form-item>
        <el-form-item label="员工类型:" prop="TypeId">
          <el-input v-model="formData.TypeId" :clearable="true"  placeholder="请输入员工类型" />
       </el-form-item>
        <el-form-item label="姓名:" prop="FullName">
          <el-input v-model="formData.FullName" :clearable="true"  placeholder="请输入姓名" />
       </el-form-item>
        <el-form-item label="性别:" prop="Gender">
          <el-input v-model="formData.Gender" :clearable="true"  placeholder="请输入性别" />
       </el-form-item>
        <el-form-item label="头像:" prop="HeadPic">
          <el-input v-model="formData.HeadPic" :clearable="true"  placeholder="请输入头像" />
       </el-form-item>
        <el-form-item label="证件类型:" prop="IDType">
          <el-input v-model="formData.IDType" :clearable="true"  placeholder="请输入证件类型" />
       </el-form-item>
        <el-form-item label="身份证号码:" prop="IDNumber">
          <el-input v-model="formData.IDNumber" :clearable="true"  placeholder="请输入身份证号码" />
       </el-form-item>
        <el-form-item label="身份证有效期:" prop="IDValidityDate">
          <el-input v-model="formData.IDValidityDate" :clearable="true"  placeholder="请输入身份证有效期" />
       </el-form-item>
        <el-form-item label="出生日期:" prop="Birthday">
          <el-date-picker v-model="formData.Birthday" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="发证机关:" prop="Organ">
          <el-input v-model="formData.Organ" :clearable="true"  placeholder="请输入发证机关" />
       </el-form-item>
        <el-form-item label="家庭地址:" prop="FamilyAddress">
          <el-input v-model="formData.FamilyAddress" :clearable="true"  placeholder="请输入家庭地址" />
       </el-form-item>
        <el-form-item label="健康状态:" prop="Health">
          <el-input v-model="formData.Health" :clearable="true"  placeholder="请输入健康状态" />
       </el-form-item>
        <el-form-item label="岗位类型:" prop="PostType">
          <el-input v-model="formData.PostType" :clearable="true"  placeholder="请输入岗位类型" />
       </el-form-item>
        <el-form-item label="岗位性质:" prop="PostNature">
          <el-input v-model="formData.PostNature" :clearable="true"  placeholder="请输入岗位性质" />
       </el-form-item>
        <el-form-item label="岗位类别:" prop="PostClass">
          <el-input v-model="formData.PostClass" :clearable="true"  placeholder="请输入岗位类别" />
       </el-form-item>
        <el-form-item label="职位:" prop="JobName">
          <el-input v-model="formData.JobName" :clearable="true"  placeholder="请输入职位" />
       </el-form-item>
        <el-form-item label="职称:" prop="JobTitle">
          <el-input v-model="formData.JobTitle" :clearable="true"  placeholder="请输入职称" />
       </el-form-item>
        <el-form-item label="员工等级:" prop="Rank">
          <el-input v-model="formData.Rank" :clearable="true"  placeholder="请输入员工等级" />
       </el-form-item>
        <el-form-item label="等级名称:" prop="RankName">
          <el-input v-model="formData.RankName" :clearable="true"  placeholder="请输入等级名称" />
       </el-form-item>
        <el-form-item label="公司ID:" prop="CompanyId">
          <el-input v-model="formData.CompanyId" :clearable="true"  placeholder="请输入公司ID" />
       </el-form-item>
        <el-form-item label="所属部门:" prop="DepartmentId">
          <el-input v-model="formData.DepartmentId" :clearable="true"  placeholder="请输入所属部门" />
       </el-form-item>
        <el-form-item label="所属部门:" prop="DepartmentClass">
          <el-input v-model="formData.DepartmentClass" :clearable="true"  placeholder="请输入所属部门" />
       </el-form-item>
        <el-form-item label="部门类别:" prop="PostId">
          <el-input v-model="formData.PostId" :clearable="true"  placeholder="请输入部门类别" />
       </el-form-item>
        <el-form-item label="岗位名称:" prop="PostName">
          <el-input v-model="formData.PostName" :clearable="true"  placeholder="请输入岗位名称" />
       </el-form-item>
        <el-form-item label="级别:" prop="GradeId">
          <el-input v-model="formData.GradeId" :clearable="true"  placeholder="请输入级别" />
       </el-form-item>
        <el-form-item label="级别分类:" prop="GradeClass">
          <el-input v-model="formData.GradeClass" :clearable="true"  placeholder="请输入级别分类" />
       </el-form-item>
        <el-form-item label="简历Id:" prop="ResumeId">
          <el-input v-model="formData.ResumeId" :clearable="true"  placeholder="请输入简历Id" />
       </el-form-item>
        <el-form-item label="入职日期:" prop="JoinDate">
          <el-date-picker v-model="formData.JoinDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="试用期截止日期:" prop="TrialEndTime">
          <el-date-picker v-model="formData.TrialEndTime" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="是否试用:" prop="IsTrial">
       </el-form-item>
        <el-form-item label="TrailAuditMark字段:" prop="TrailAuditMark">
          <el-input v-model.number="formData.TrailAuditMark" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="STrailAuditMark字段:" prop="STrailAuditMark">
          <el-input v-model.number="formData.STrailAuditMark" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="加薪日期:" prop="TrailRaiseDate">
          <el-date-picker v-model="formData.TrailRaiseDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="是否试用提升:" prop="IsTrailRaise">
       </el-form-item>
        <el-form-item label="ID卡号:" prop="IdCard">
          <el-input v-model="formData.IdCard" :clearable="true"  placeholder="请输入ID卡号" />
       </el-form-item>
        <el-form-item label="岗位奖金生效日期:" prop="EffectiveDate">
          <el-date-picker v-model="formData.EffectiveDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="国籍:" prop="Country">
          <el-input v-model="formData.Country" :clearable="true"  placeholder="请输入国籍" />
       </el-form-item>
        <el-form-item label="籍贯:" prop="Native">
          <el-input v-model="formData.Native" :clearable="true"  placeholder="请输入籍贯" />
       </el-form-item>
        <el-form-item label="民族:" prop="Nation">
          <el-input v-model="formData.Nation" :clearable="true"  placeholder="请输入民族" />
       </el-form-item>
        <el-form-item label="最高学历:" prop="Education">
          <el-input v-model="formData.Education" :clearable="true"  placeholder="请输入最高学历" />
       </el-form-item>
        <el-form-item label="手提电话:" prop="Mobile">
          <el-input v-model="formData.Mobile" :clearable="true"  placeholder="请输入手提电话" />
       </el-form-item>
        <el-form-item label="婚姻状况:" prop="Marriage">
          <el-input v-model="formData.Marriage" :clearable="true"  placeholder="请输入婚姻状况" />
       </el-form-item>
        <el-form-item label="考勤卡号:" prop="AttendanceCode">
          <el-input v-model="formData.AttendanceCode" :clearable="true"  placeholder="请输入考勤卡号" />
       </el-form-item>
        <el-form-item label="工齡起算日:" prop="WorkageCountOn">
          <el-date-picker v-model="formData.WorkageCountOn" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="工资薪酬ID:" prop="SalaryId">
          <el-input v-model="formData.SalaryId" :clearable="true"  placeholder="请输入工资薪酬ID" />
       </el-form-item>
        <el-form-item label="岗位奖金类型:" prop="PostBonusId">
          <el-input v-model="formData.PostBonusId" :clearable="true"  placeholder="请输入岗位奖金类型" />
       </el-form-item>
        <el-form-item label="岗位奖金金额:" prop="BonusWage">
          <el-input-number v-model="formData.BonusWage" :precision="2" :clearable="true"></el-input-number>
       </el-form-item>
        <el-form-item label="放假组别:" prop="HolidayGroupId">
          <el-input v-model="formData.HolidayGroupId" :clearable="true"  placeholder="请输入放假组别" />
       </el-form-item>
        <el-form-item label="考勤组别:" prop="AttendanceGroupId">
          <el-input v-model="formData.AttendanceGroupId" :clearable="true"  placeholder="请输入考勤组别" />
       </el-form-item>
        <el-form-item label="地区:" prop="Area">
          <el-input v-model="formData.Area" :clearable="true"  placeholder="请输入地区" />
       </el-form-item>
        <el-form-item label="紧急联系人:" prop="UrgentContacts">
          <el-input v-model="formData.UrgentContacts" :clearable="true"  placeholder="请输入紧急联系人" />
       </el-form-item>
        <el-form-item label="紧急联系电话:" prop="UrgentContactPhone">
          <el-input v-model="formData.UrgentContactPhone" :clearable="true"  placeholder="请输入紧急联系电话" />
       </el-form-item>
        <el-form-item label="入职介绍人:" prop="Recommender">
          <el-input v-model="formData.Recommender" :clearable="true"  placeholder="请输入入职介绍人" />
       </el-form-item>
        <el-form-item label="介绍人电话:" prop="RecommMobile">
          <el-input v-model="formData.RecommMobile" :clearable="true"  placeholder="请输入介绍人电话" />
       </el-form-item>
        <el-form-item label="状态:" prop="Status">
          <el-input v-model.number="formData.Status" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="删除标记:" prop="DeleteMark">
          <el-input v-model.number="formData.DeleteMark" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="修改时间:" prop="LeaveDate">
          <el-date-picker v-model="formData.LeaveDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="有效标志:" prop="EnabledMark">
          <el-input v-model.number="formData.EnabledMark" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="备注:" prop="Description">
          <el-input v-model="formData.Description" :clearable="true"  placeholder="请输入备注" />
       </el-form-item>
        <el-form-item label="创建时间:" prop="CreateDate">
          <el-date-picker v-model="formData.CreateDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="创建用户主键:" prop="CreateUserId">
          <el-input v-model="formData.CreateUserId" :clearable="true"  placeholder="请输入创建用户主键" />
       </el-form-item>
        <el-form-item label="创建用户:" prop="CreateUserName">
          <el-input v-model="formData.CreateUserName" :clearable="true"  placeholder="请输入创建用户" />
       </el-form-item>
        <el-form-item label="修改时间:" prop="ModifyDate">
          <el-date-picker v-model="formData.ModifyDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="修改用户主键:" prop="ModifyUserId">
          <el-input v-model="formData.ModifyUserId" :clearable="true"  placeholder="请输入修改用户主键" />
       </el-form-item>
        <el-form-item label="修改用户:" prop="ModifyUserName">
          <el-input v-model="formData.ModifyUserName" :clearable="true"  placeholder="请输入修改用户" />
       </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
          <el-button type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import {
  createZSHRMEmployee,
  updateZSHRMEmployee,
  findZSHRMEmployee
} from '@/api/ZSHRMEmployee'

defineOptions({
    name: 'ZSHRMEmployeeForm'
})

// 自动获取字典
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref, reactive } from 'vue'

const route = useRoute()
const router = useRouter()

const type = ref('')
const formData = ref({
            EmployeeId: '',
            EnCode: '',
            TypeId: '',
            FullName: '',
            Gender: '',
            HeadPic: '',
            IDType: '',
            IDNumber: '',
            IDValidityDate: '',
            Birthday: new Date(),
            Organ: '',
            FamilyAddress: '',
            Health: '',
            PostType: '',
            PostNature: '',
            PostClass: '',
            JobName: '',
            JobTitle: '',
            Rank: '',
            RankName: '',
            CompanyId: '',
            DepartmentId: '',
            DepartmentClass: '',
            PostId: '',
            PostName: '',
            GradeId: '',
            GradeClass: '',
            ResumeId: '',
            JoinDate: new Date(),
            TrialEndTime: new Date(),
            TrailAuditMark: 0,
            STrailAuditMark: 0,
            TrailRaiseDate: new Date(),
            IdCard: '',
            EffectiveDate: new Date(),
            Country: '',
            Native: '',
            Nation: '',
            Education: '',
            Mobile: '',
            Marriage: '',
            AttendanceCode: '',
            WorkageCountOn: new Date(),
            SalaryId: '',
            PostBonusId: '',
            BonusWage: 0,
            HolidayGroupId: '',
            AttendanceGroupId: '',
            Area: '',
            UrgentContacts: '',
            UrgentContactPhone: '',
            Recommender: '',
            RecommMobile: '',
            Status: 0,
            DeleteMark: 0,
            LeaveDate: new Date(),
            EnabledMark: 0,
            Description: '',
            CreateDate: new Date(),
            CreateUserId: '',
            CreateUserName: '',
            ModifyDate: new Date(),
            ModifyUserId: '',
            ModifyUserName: '',
        })
// 验证规则
const rule = reactive({
})

const elFormRef = ref()

// 初始化方法
const init = async () => {
 // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (route.query.id) {
      const res = await findZSHRMEmployee({ ID: route.query.id })
      if (res.code === 0) {
        formData.value = res.data.rezSHRMEmployee
        type.value = 'update'
      }
    } else {
      type.value = 'create'
    }
}

init()
// 保存按钮
const save = async() => {
      elFormRef.value?.validate( async (valid) => {
         if (!valid) return
            let res
           switch (type.value) {
             case 'create':
               res = await createZSHRMEmployee(formData.value)
               break
             case 'update':
               res = await updateZSHRMEmployee(formData.value)
               break
             default:
               res = await createZSHRMEmployee(formData.value)
               break
           }
           if (res.code === 0) {
             ElMessage({
               type: 'success',
               message: '创建/更改成功'
             })
           }
       })
}

// 返回按钮
const back = () => {
    router.go(-1)
}

</script>

<style>
</style>
